package com.zzsy.shoppingpro.community.fragment;

import android.view.View;
import android.widget.ListView;

import com.zzsy.shoppingpro.R;
import com.zzsy.shoppingpro.app.Config;
import com.zzsy.shoppingpro.base.BaseFragment;
import com.zzsy.shoppingpro.basebean.BaseBean;
import com.zzsy.shoppingpro.community.adapter.HotPostListViewAdapter;
import com.zzsy.shoppingpro.community.adapter.NewPostListViewAdapter;
import com.zzsy.shoppingpro.community.bean.HotPostBean;
import com.zzsy.shoppingpro.community.bean.NewPostBean;
import com.zzsy.shoppingpro.http.BaseCallback;
import com.zzsy.shoppingpro.http.RetrofitHelper;
import com.zzsy.shoppingpro.server.MainService;

import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by Administrator on 2019/8/21 0021.
 */

public class NewPostFragment extends BaseFragment {

    private ListView lv_new_post;

    @Override
    public View initView() {
        View view = View.inflate(context, R.layout.fragment_new_post, null);
        lv_new_post = view.findViewById(R.id.lv_new_post);
        return view;
    }

    /**
     * 网络请求数据
     * */
    @Override
    public void initData() {

        RetrofitHelper.create(MainService.class, Config.BASE_URL_JSON)
                .getCommunityNewData()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseCallback<BaseBean<List<NewPostBean>>>() {
                    @Override
                    public void success(BaseBean<List<NewPostBean>> listBaseBean) {
                        NewPostListViewAdapter adapter = new NewPostListViewAdapter(context,listBaseBean.getData());
                        lv_new_post.setAdapter(adapter);
                    }

                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });


    }

}
